using UnityEngine;
using System.Collections;

public class MenuLevels : MonoBehaviour
{
	public GUIStyle mNiveles;
	public GUIStyle mCasilla;
	public GUIStyle mLetra;
	public GUIStyle mCandado;


	void OnGUI()
	{


		float lfWidth = (float)Screen.width / 320.0f;
		float lfHeight = (float)Screen.height / 480.0f;


		GUI.Label(new Rect(0, 0, Screen.width, Screen.height), "", mNiveles);

		//Primera fila

		float liIntervaloX = 60.0f;
		float liComienzoX = 20.0f;
		float liIntervaloY = 70.0f;
		float liComienzoY = 120.0f;

		float liAnchoCasilla = 47.0f;
		float liAltoCasilla = 47.0f;

		int liAnchoTablero = 5;
		int liAltoTablero = 5;


		//string lsValor = SQL.SP.msNombre.ToString() + " - " + SQL.SP.miLevelMax.ToString() + " + " +  SQL.SP.miLevelActual.ToString() + " <> " + SQL.SP.msDispositivo.ToString();
		//GUI.Label(new Rect(4, 40, 400, 400), lsValor.ToString());

		int liLevelMax = SQL.SP.SelectLevelMax();
		
		//mLetra.fontSize = (int)(mLetra.fontSize * lfHeight);
		
		for (int j = 0; j < liAltoTablero; j++)
		{
			for (int i = 0; i < liAnchoTablero; i++)
			{
				int liLevel = j * liAltoTablero + i + 1;

				//Condicion si nivel activo
				if (liLevel <= liLevelMax) //level max que has conseguido llegar
				{
					if ((GUI.Button(new Rect((i * liIntervaloX) * lfWidth + liComienzoX * lfWidth,
											 (j * liIntervaloY) * lfHeight + liComienzoY * lfHeight,
											 liAnchoCasilla * lfWidth,
											 liAltoCasilla * lfHeight), "", mCasilla)))
					{
						
						
						
						//CargaInicial(liLevel);
						SQL.SP.UpdateLevelActual(liLevel);
						Application.LoadLevel(2);
						//gameState = BreakoutGameState.playing;
					}
					
					
					GUI.Label(new Rect((i * liIntervaloX) * lfWidth + liComienzoX * lfWidth,
											 (j * liIntervaloY) * lfHeight + liComienzoY * lfHeight,
											 liAnchoCasilla * lfWidth, liAltoCasilla * lfHeight), 
						                     liLevel.ToString(), mLetra);					
					
				}

				else
				{
					if ((GUI.Button(new Rect((i * liIntervaloX) * lfWidth + liComienzoX * lfWidth,
											 (j * liIntervaloY) * lfHeight + liComienzoY * lfHeight,
											 liAnchoCasilla * lfWidth,
																 liAltoCasilla * lfHeight), "", mCandado)))
					{

						//CargaInicial(liLevel);
						//gameState = BreakoutGameState.playing;
					}
				}

			}
		}

	}
}
